'use strict';

var serve = {};
(function(_) {
    _.request = function(param, methodVal = 'GET') {
    	return new Promise((resolve, reject) => {
    		param.v = param.v || '/v1'; //接口版本
    		// let methodVal = param.methodVal,
    		uni.request({
    			url: _.apiUrl() + param.v + param.url, 
    			data: param.data,
    			method: methodVal,
    			success: (res) => { 
    				if(res&&res.statusCode==200){
    					if(res.data.code == 199) {
    						uni.navigateTo({
    						    url: '/pages/my/login'
    						});
    						return ;
    					}
    					resolve(res.data);
    				}else{
    					uni.showToast({
    						title:res.message,
    						icon:'none'
    					});
    				}
    				
    			},
    			fail: (error) => {
    				reject(error);
    			},
    			complete: () => {
    				uni.hideLoading();
    				uni.stopPullDownRefresh();
    			}
    		});
    	});
    };
    _.apiUrl = function() {
        return 'https://hdsq.aoorange.cn/api';
        // return 'http://hdsq.com/api';
    };
    _.imgUrl = function() {
        return 'https://hdsq.aoorange.cn/attachment/';
        // return 'http://hdsq.com/attachment/';
    };
})(serve);


module.exports = {
    request: serve.request,
    apiUrl : serve.apiUrl,
    imgUrl : serve.imgUrl,
};
